package org.atlantis.mongo.datatype;

import org.atlantis.mongo.MongoFactory;
import org.atlantis.mongo.TrialUtils;
import org.bson.types.ObjectId;

import com.mongodb.BasicDBObject;
import com.mongodb.CommandResult;
import com.mongodb.DBCollection;

public class DataTypeTrial {
	
	// 数据大小：11.443MB
	public void longTypes() {
		DBCollection coll = MongoFactory.getDB().getCollection("trial.longtypes");
		for (long i = 10000000; i < 10600000; i++) {
			coll.insert(new BasicDBObject("_id", i));
		}
		CommandResult cr = coll.getStats();
		printSize(cr);
	}
	
	// 数据大小：dataSize: 13.732MB
	public void objectIdTypes() {
		DBCollection coll = MongoFactory.getDB().getCollection("trial.objidtypes");
		for (int i = 0; i < 600000; i++) {
			coll.insert(new BasicDBObject("_id", new ObjectId()));
		}
		CommandResult cr = coll.getStats();
		printSize(cr);
	}

	private void printSize(CommandResult cr) {
		String dataSize = TrialUtils.formatSize(cr.getLong("size"));
		String nameIndexSize = TrialUtils.formatSize((cr.getLong("size")));
		System.out.println("dataSize: " + dataSize);
		System.out.println("nameIndexSize: " + nameIndexSize);
	}

	public static void main(String[] args) {
		DataTypeTrial trial = new DataTypeTrial();
		trial.objectIdTypes();
	}
}
